package com.xinwei.common;

import com.xinwei.excpetion.ManagerExceptionEnmu;

/**
 * 描述：  通用返回对象
 */

public class ApiRestResponse {

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static int getOkCode() {
        return OK_CODE;
    }

    public static String getOkMsg() {
        return OK_MSG;
    }

    private Integer status;

    private String msg;

    private Object data;

    private static final int OK_CODE = 10000;

    private static final String OK_MSG = "SUCCESS";

    public ApiRestResponse(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ApiRestResponse() {
        this(OK_CODE, OK_MSG);
    }

    //成功不带数据
    public static ApiRestResponse success() {
        return new ApiRestResponse();
    }

    //成功带数据
    public static ApiRestResponse success(Object result) {
        ApiRestResponse response = new ApiRestResponse();
        response.setData(result);
        return response;
    }

    //失败
    public static ApiRestResponse error(ManagerExceptionEnmu ex) {
        return new ApiRestResponse(ex.getCode(), ex.getMsg());
    }

    public static ApiRestResponse error(Integer code, String msg) {
        return new ApiRestResponse(code, msg);
    }

}
